package com.siysoft.tc.reservation.action;

import java.sql.Timestamp;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.siysoft.tc.base.bean.bo.AvatarBo;
import com.siysoft.tc.base.bean.bo.MessageBo;
import com.siysoft.tc.base.bean.bo.PaginationBo;
import com.siysoft.tc.base.bean.bo.ReservationBo;
import com.siysoft.tc.base.bean.bo.StudentEvaluationTotalBo;
import com.siysoft.tc.base.bean.bo.TeacherEvaluationTotalBo;
import com.siysoft.tc.reservation.service.IReservationService;
import com.siysoft.util.COMMON;
import com.siysoft.util.OutTradeNo;
import com.tc.base.controller.BaseController;
import com.siysoft.tc.remind.service.IRemindService;

@Controller
@RequestMapping(value = "/app/reservation")
public class ReservationController extends BaseController{
	@Autowired
	IReservationService reservationService;
	
	@Autowired
	IRemindService remindService;
	
	/**
	 * 
	 * @param request
	 * @param response
	 */
	
	@RequestMapping(value = "/all")
	public void all(HttpServletRequest request,
			HttpServletResponse response){
		try{
			if( COMMON.isnull(request.getParameter("id"))
					|| COMMON.isnull(request.getParameter("school"))
					)
			{
				this.responseFail(response, -32602, "参数无效", "指定参数不符合服务接口定义");
				return ;
			}
			Integer user_id = Integer.valueOf(request.getParameter("id").toString());
			String school = request.getParameter("school").toString();
			
			List<ReservationBo> rb = reservationService.getAll(user_id, school);
			
			JSONObject obj = new JSONObject();
			obj.accumulate("reservation", rb);
			String format_json = this.FormatJson(0, "", Object2Json(obj));
			this.responseSuccess(response, format_json, 0);
			return;
		}
		catch(Exception e){
			e.printStackTrace();
			this.responseFail(response, -32602, "服务器有点忙，请过会重试", "");
			return ;
		}
	}
	
	/**
	 * 
	 * @param request
	 * @param response
	 */
	
	@RequestMapping(value = "/search")
	public void search(HttpServletRequest request,
			HttpServletResponse response){
		try{
			if( COMMON.isnull(request.getParameter("id"))
					|| COMMON.isnull(request.getParameter("school"))
					)
			{
				this.responseFail(response, -32602, "参数无效", "指定参数不符合服务接口定义");
				return ;
			}
			Integer user_id = Integer.valueOf(request.getParameter("id").toString());
			String lecture = request.getParameter("lecture").toString();
			String course = request.getParameter("course").toString();
			String school = request.getParameter("school").toString();
			
			List<ReservationBo> rb = reservationService.search(user_id, lecture, course, school);
			
			JSONObject obj = new JSONObject();
			obj.accumulate("reservation", rb);
			String format_json = this.FormatJson(0, "", Object2Json(obj));
			this.responseSuccess(response, format_json, 0);
			return;
		}
		catch(Exception e){
			e.printStackTrace();
			this.responseFail(response, -32602, "服务器有点忙，请过会重试", "");
			return ;
		}
	}
	
	/**
	 * 
	 * @param request
	 * @param response
	 */
	
	@RequestMapping(value = "/search2")
	public void search2(HttpServletRequest request,
			HttpServletResponse response){
		try{
			if( COMMON.isnull(request.getParameter("select_str"))
					|| COMMON.isnull(request.getParameter("id"))
					|| COMMON.isnull(request.getParameter("school"))
					)
			{
				this.responseFail(response, -32602, "参数无效", "指定参数不符合服务接口定义");
			}
			String select_str = request.getParameter("select_str").toString();
			Integer user_id = Integer.valueOf(request.getParameter("id").toString());
			String school = request.getParameter("school").toString();
			
			List<ReservationBo> rb = reservationService.search2(user_id, select_str, school);
			
			JSONObject obj = new JSONObject();
			obj.accumulate("reservation", COMMON.NulltoBlank(rb));
			String format_json = this.FormatJson(0, "", Object2Json(obj));
			this.responseSuccess(response, format_json, 0);
			return;
		}
		catch(Exception e){
			e.printStackTrace();
			this.responseFail(response, -32602, "服务器有点忙，请过会重试", "");
			return ;
		}
	}
	
	/**
	 * 
	 * @param request
	 * @param response
	 */
	
	@RequestMapping(value = "/pay")
	public void pay(HttpServletRequest request,
			HttpServletResponse response){
		try{
			if( COMMON.isnull(request.getParameter("user_id"))
					|| COMMON.isnull(request.getParameter("reservation_id")))
			{
				this.responseFail(response, -32602, "参数无效", "指定参数不符合服务接口定义");
				return ;
			}
			Integer user_id = Integer.valueOf(request.getParameter("user_id").toString());
			Integer reservation_id = Integer.valueOf(request.getParameter("reservation_id").toString());
			
			String result = reservationService.pay(user_id, reservation_id);
			
			JSONObject obj = new JSONObject();
			obj.accumulate("result", result);
			String format_json = this.FormatJson(0, "", Object2Json(obj));
			this.responseSuccess(response, format_json, 0);
			return;
		}
		catch(Exception e){
			e.printStackTrace();
			this.responseFail(response, -32602, "服务器有点忙，请过会重试", "");
			return ;
		}
	}
	
	/**
	 * 
	 * @param request
	 * @param response
	 */
	
	@RequestMapping(value = "/join")
	public void join(HttpServletRequest request,
			HttpServletResponse response){
		try{
			if( COMMON.isnull(request.getParameter("user_id"))
					|| COMMON.isnull(request.getParameter("reservation_id"))
					|| COMMON.isnull(request.getParameter("wage"))
					|| COMMON.isnull(request.getParameter("period"))
					)
			{
				this.responseFail(response, -32602, "参数无效", "指定参数不符合服务接口定义");
				return ;
			}
			Integer user_id = Integer.valueOf(request.getParameter("user_id").toString());
			Integer reservation_id = Integer.valueOf(request.getParameter("reservation_id").toString());
			Integer wage = Integer.valueOf(request.getParameter("wage").toString());
			Integer period = Integer.valueOf(request.getParameter("period").toString());
			
			String result = reservationService.join(user_id, reservation_id, wage, period);
			
			JSONObject obj = new JSONObject();
			obj.accumulate("result", result);
			String format_json = this.FormatJson(0, "", Object2Json(obj));
			this.responseSuccess(response, format_json, 0);
			return;
		}
		catch(Exception e){
			e.printStackTrace();
			this.responseFail(response, -32602, "服务器有点忙，请过会重试", "");
			return ;
		}
	}
	
	/**
	 * 
	 * @param request
	 * @param response
	 */
	
	@RequestMapping(value = "/agree")
	public void agree(HttpServletRequest request,
			HttpServletResponse response){
		try{
			if( COMMON.isnull(request.getParameter("user_id"))
					|| COMMON.isnull(request.getParameter("reservation_id"))
					)
			{
				this.responseFail(response, -32602, "参数无效", "指定参数不符合服务接口定义");
				return ;
			}
			Integer user_id = Integer.valueOf(request.getParameter("user_id").toString());
			Integer reservation_id = Integer.valueOf(request.getParameter("reservation_id").toString());
			
			String result = reservationService.agree(user_id, reservation_id);
			
			JSONObject obj = new JSONObject();
			obj.accumulate("result", result);
			String format_json = this.FormatJson(0, "", Object2Json(obj));
			this.responseSuccess(response, format_json, 0);
			return;
		}
		catch(Exception e){
			e.printStackTrace();
			this.responseFail(response, -32602, "服务器有点忙，请过会重试", "");
			return ;
		}
	}
	
	/**
	 * 
	 * @param request
	 * @param response
	 */
	
	@RequestMapping(value = "/begin")
	public void begin(HttpServletRequest request,
			HttpServletResponse response){
		try{
			if( COMMON.isnull(request.getParameter("reservation_id"))
					)
			{
				this.responseFail(response, -32602, "参数无效", "指定参数不符合服务接口定义");
				return ;
			}
			Integer reservation_id = Integer.valueOf(request.getParameter("reservation_id").toString());
			
			String result = reservationService.begin(reservation_id);
			
			JSONObject obj = new JSONObject();
			obj.accumulate("result", result);
			String format_json = this.FormatJson(0, "", Object2Json(obj));
			this.responseSuccess(response, format_json, 0);
			return;
		}
		catch(Exception e){
			e.printStackTrace();
			this.responseFail(response, -32602, "服务器有点忙，请过会重试", "");
			return ;
		}
	}
	
	/**
	 * 
	 * @param request
	 * @param response
	 */
	
	@RequestMapping(value = "/finish")
	public void finish(HttpServletRequest request,
			HttpServletResponse response){
		try{
			if( COMMON.isnull(request.getParameter("reservation_id"))
					)
			{
				this.responseFail(response, -32602, "参数无效", "指定参数不符合服务接口定义");
				return ;
			}
			Integer reservation_id = Integer.valueOf(request.getParameter("reservation_id").toString());
			
			String result = reservationService.finish(reservation_id);
			
			JSONObject obj = new JSONObject();
			obj.accumulate("result", result);
			String format_json = this.FormatJson(0, "", Object2Json(obj));
			this.responseSuccess(response, format_json, 0);
			return;
		}
		catch(Exception e){
			e.printStackTrace();
			this.responseFail(response, -32602, "服务器有点忙，请过会重试", "");
			return ;
		}
	}
	
	/**
	 * 
	 * @param request
	 * @param response
	 */
	
	@RequestMapping(value = "/finish_evaluate")
	public void finish_evaluate(HttpServletRequest request,
			HttpServletResponse response){
		try{
			if( COMMON.isnull(request.getParameter("user_id"))
					|| COMMON.isnull(request.getParameter("reservation_id"))
					)
			{
				this.responseFail(response, -32602, "参数无效", "指定参数不符合服务接口定义");
				return ;
			}
			Integer user_id = Integer.valueOf(request.getParameter("user_id").toString());
			Integer reservation_id = Integer.valueOf(request.getParameter("reservation_id").toString());
			
			String result = reservationService.finish_evaluate(user_id, reservation_id);
			
			JSONObject obj = new JSONObject();
			obj.accumulate("result", result);
			String format_json = this.FormatJson(0, "", Object2Json(obj));
			this.responseSuccess(response, format_json, 0);
			return;
		}
		catch(Exception e){
			e.printStackTrace();
			this.responseFail(response, -32602, "服务器有点忙，请过会重试", "");
			return ;
		}
	}
	
	/**
	 * 
	 * @param request
	 * @param response
	 */
	
	@RequestMapping(value = "/drop_out")
	public String drop_out(HttpServletRequest request,
			HttpServletResponse response){
		try{
			if( COMMON.isnull(request.getParameter("user_id"))
					|| COMMON.isnull(request.getParameter("reservation_id"))
					)
			{
				this.responseFail(response, -32602, "参数无效", "指定参数不符合服务接口定义");
				return "error";
			}
			Integer user_id = Integer.valueOf(request.getParameter("user_id").toString());
			Integer reservation_id = Integer.valueOf(request.getParameter("reservation_id").toString());
			
			String result = reservationService.drop_out(user_id, reservation_id);
			
			/*JSONObject obj = new JSONObject();
			obj.accumulate("result", result);
			String format_json = this.FormatJson(0, "", Object2Json(obj));
			this.responseSuccess(response, format_json, 0);*/
			return "personal";
		}
		catch(Exception e){
			e.printStackTrace();
			this.responseFail(response, -32602, "服务器有点忙，请过会重试", "");
			return "error";
		}
	}
	
	/**
	 * 
	 * @param request
	 * @param response
	 */
	
	@RequestMapping(value = "/classroom")
	public void classroom(HttpServletRequest request,
			HttpServletResponse response){
		try{
			if( COMMON.isnull(request.getParameter("number"))
					|| COMMON.isnull(request.getParameter("limit"))
					|| COMMON.isnull(request.getParameter("offset"))
					)
			{
				this.responseFail(response, -32602, "参数无效", "指定参数不符合服务接口定义");
				return ;
			}
			String number = request.getParameter("number").toString();
			Integer limit = Integer.valueOf(request.getParameter("limit").toString());
			Integer offset = Integer.valueOf(request.getParameter("offset").toString());
			
			PaginationBo pb = new PaginationBo(limit, offset, 0);
			List<MessageBo> message = reservationService.getClassroom(number, pb);
			
			JSONObject obj = new JSONObject();
			obj.accumulate("message", COMMON.NulltoBlank(message));
			obj.accumulate("pagination", pb);
			String format_json = this.FormatJson(0, "", Object2Json(obj));
			this.responseSuccess(response, format_json, 0);
			return;
		}
		catch(Exception e){
			e.printStackTrace();
			this.responseFail(response, -32602, "服务器有点忙，请过会重试", "");
			return ;
		}
	}
	
	/**
	 * 
	 * @param request
	 * @param response
	 */
	
	@RequestMapping(value = "/reply")
	public void reply(HttpServletRequest request,
			HttpServletResponse response){
		try{
			if( COMMON.isnull(request.getParameter("id"))
					|| COMMON.isnull(request.getParameter("number"))
					|| COMMON.isnull(request.getParameter("message"))
					)
			{
				this.responseFail(response, -32602, "参数无效", "指定参数不符合服务接口定义");
				return ;
			}
			Integer id = Integer.valueOf(request.getParameter("id").toString());
			String number = request.getParameter("number").toString();
			String message = request.getParameter("message").toString();
			
			Integer result = reservationService.reply(id, number, message);
			
			JSONObject obj = new JSONObject();
			obj.accumulate("result", result);
			String format_json = this.FormatJson(0, "", Object2Json(obj));
			this.responseSuccess(response, format_json, 0);
			return;
		}
		catch(Exception e){
			e.printStackTrace();
			this.responseFail(response, -32602, "服务器有点忙，请过会重试", "");
			return ;
		}
	}
	
	/**
	 * 
	 * @param request
	 * @param response
	 */
	
	@RequestMapping(value = "/state")
	public void state(HttpServletRequest request,
			HttpServletResponse response){
		try{
			if( COMMON.isnull(request.getParameter("id"))
					|| COMMON.isnull(request.getParameter("number"))
					|| COMMON.isnull(request.getParameter("state"))
					)
			{
				this.responseFail(response, -32602, "参数无效", "指定参数不符合服务接口定义");
				return ;
			}
			Integer id = Integer.valueOf(request.getParameter("id").toString());
			String number = request.getParameter("number").toString();
			Integer state = Integer.valueOf(request.getParameter("state").toString());
			
			String result = reservationService.state(id, number, state);
			
			JSONObject obj = new JSONObject();
			obj.accumulate("result", result);
			String format_json = this.FormatJson(0, "", Object2Json(obj));
			this.responseSuccess(response, format_json, 0);
			return;
		}
		catch(Exception e){
			e.printStackTrace();
			this.responseFail(response, -32602, "服务器有点忙，请过会重试", "");
			return ;
		}
	}
	
	/**
	 * 
	 * @param request
	 * @param response
	 */
	
	@RequestMapping(value = "/teacheravatar")
	public void teacheravatar(HttpServletRequest request,
			HttpServletResponse response){
		try{
			if( COMMON.isnull(request.getParameter("reservation_id"))
					)
			{
				this.responseFail(response, -32602, "参数无效", "指定参数不符合服务接口定义");
				return ;
			}
			Integer reservation_id = Integer.valueOf(request.getParameter("reservation_id").toString());
			
			String avatar_url = reservationService.getTeacherAvatar(reservation_id);
			
			JSONObject obj = new JSONObject();
			obj.accumulate("avatar_url", avatar_url);
			String format_json = this.FormatJson(0, "", Object2Json(obj));
			this.responseSuccess(response, format_json, 0);
			return;
		}
		catch(Exception e){
			e.printStackTrace();
			this.responseFail(response, -32602, "服务器有点忙，请过会重试", "");
			return ;
		}
	}
	
	/**
	 * 
	 * @param request
	 * @param response
	 */
	
	@RequestMapping(value = "/evaluatestudent")
	public void evaluatestudent(HttpServletRequest request,
			HttpServletResponse response){
		try{
			if( COMMON.isnull(request.getParameter("student_id"))
					|| COMMON.isnull(request.getParameter("reservation_id"))
					|| COMMON.isnull(request.getParameter("patience"))
					|| COMMON.isnull(request.getParameter("professionalism"))
					|| COMMON.isnull(request.getParameter("expression"))
					|| COMMON.isnull(request.getParameter("usefulness"))
					|| COMMON.isnull(request.getParameter("interaction"))
					|| COMMON.isnull(request.getParameter("isgoal"))
					)
			{
				this.responseFail(response, -32602, "参数无效", "指定参数不符合服务接口定义");
				return ;
			}
			Integer student_id = Integer.valueOf(request.getParameter("student_id").toString());
			Integer reservation_id = Integer.valueOf(request.getParameter("reservation_id").toString());
			Integer patience = Integer.valueOf(request.getParameter("patience").toString());
			Integer professionalism = Integer.valueOf(request.getParameter("professionalism").toString());
			Integer expression = Integer.valueOf(request.getParameter("expression").toString());
			Integer usefulness = Integer.valueOf(request.getParameter("usefulness").toString());
			Integer interaction = Integer.valueOf(request.getParameter("interaction").toString());
			String detail = request.getParameter("detail").toString();
			Integer isgoal = Integer.valueOf(request.getParameter("isgoal").toString());
			
			String result = reservationService.evaluateStudent(student_id, reservation_id,
					patience, professionalism, expression, usefulness, interaction, detail, isgoal);
			
			JSONObject obj = new JSONObject();
			obj.accumulate("result", result);
			String format_json = this.FormatJson(0, "", Object2Json(obj));
			this.responseSuccess(response, format_json, 0);
			return;
		}
		catch(Exception e){
			e.printStackTrace();
			this.responseFail(response, -32602, "服务器有点忙，请过会重试", "");
			return ;
		}
	}
	
	/**
	 * 
	 * @param request
	 * @param response
	 */
	
	@RequestMapping(value = "/student_list")
	public void student(HttpServletRequest request,
			HttpServletResponse response){
		try{
			if( COMMON.isnull(request.getParameter("reservation_id"))
					|| COMMON.isnull(request.getParameter("limit"))
					|| COMMON.isnull(request.getParameter("offset"))
					)
			{
				this.responseFail(response, -32602, "参数无效", "指定参数不符合服务接口定义");
				return ;
			}
			Integer reservation_id = Integer.valueOf(request.getParameter("reservation_id").toString());
			Integer limit = Integer.valueOf(request.getParameter("limit").toString());
			Integer offset = Integer.valueOf(request.getParameter("offset").toString());
			
			PaginationBo pb = new PaginationBo(limit, offset, 0);
			List<AvatarBo> avatar = reservationService.getstudent(reservation_id, pb);
			
			JSONObject obj = new JSONObject();
			obj.accumulate("avatar", COMMON.NulltoBlank(avatar));
			obj.accumulate("pagination", pb);
			String format_json = this.FormatJson(0, "", Object2Json(obj));
			this.responseSuccess(response, format_json, 0);
			return;
		}
		catch(Exception e){
			e.printStackTrace();
			this.responseFail(response, -32602, "服务器有点忙，请过会重试", "");
			return ;
		}
	}
	
	/**
	 * 
	 * @param request
	 * @param response
	 */
	
	@RequestMapping(value = "/evaluateteacher")
	public void evaluateteacher(HttpServletRequest request,
			HttpServletResponse response){
		try{
			if( COMMON.isnull(request.getParameter("teacher_id"))
					|| COMMON.isnull(request.getParameter("reservation_id"))
					|| COMMON.isnull(request.getParameter("evaluation"))
					)
			{
				this.responseFail(response, -32602, "参数无效", "指定参数不符合服务接口定义");
				return ;
			}
			Integer teacher_id = Integer.valueOf(request.getParameter("teacher_id").toString());
			Integer reservation_id = Integer.valueOf(request.getParameter("reservation_id").toString());
			String evaluation_str = request.getParameter("evaluation").toString();
			JSONArray evaluation = JSONArray.fromObject(evaluation_str);
			
			Integer result = reservationService.evaluateTeacher(teacher_id, reservation_id, evaluation);
			
			JSONObject obj = new JSONObject();
			obj.accumulate("result", result);
			String format_json = this.FormatJson(0, "", Object2Json(obj));
			this.responseSuccess(response, format_json, 0);
			return;
		}
		catch(Exception e){
			e.printStackTrace();
			this.responseFail(response, -32602, "服务器有点忙，请过会重试", "");
			return ;
		}
	}
	
	/**
	 * 
	 * @param request
	 * @param response
	 */
	
	@RequestMapping(value = "/totalevaluationteacher")
	public void totalevaluation(HttpServletRequest request,
			HttpServletResponse response){
		try{
			if( COMMON.isnull(request.getParameter("id"))
					)
			{
				this.responseFail(response, -32602, "参数无效", "指定参数不符合服务接口定义");
				return ;
			}
			Integer id = Integer.valueOf(request.getParameter("id").toString());
			
			TeacherEvaluationTotalBo tetb = reservationService.get_teacher_evaluation_total(id);
			
			if(tetb == null){
				this.responseFail(response, -32602, "暂无学生评价", "");
				return ;
			}
			JSONObject obj = new JSONObject();
			obj.accumulate("teacher_evaluation_total", tetb);
			String format_json = this.FormatJson(0, "", Object2Json(obj));
			this.responseSuccess(response, format_json, 0);
			return;
		}
		catch(Exception e){
			e.printStackTrace();
			this.responseFail(response, -32602, "服务器有点忙，请过会重试", "");
			return ;
		}
	}
	
	/**
	 * 
	 * @param request
	 * @param response
	 */
	
	@RequestMapping(value = "/totalevaluationstudent")
	public void totalevaluationstudent(HttpServletRequest request,
			HttpServletResponse response){
		try{
			if( COMMON.isnull(request.getParameter("user_id"))
					|| COMMON.isnull(request.getParameter("reservation_id"))
					)
			{
				this.responseFail(response, -32602, "参数无效", "指定参数不符合服务接口定义");
				return ;
			}
			Integer user_id = Integer.valueOf(request.getParameter("user_id").toString());
			Integer reservation_id = Integer.valueOf(request.getParameter("reservation_id").toString());
			
			StudentEvaluationTotalBo setb = reservationService.get_student_evaluation_total(user_id, reservation_id);
			
			if(setb == null){
				this.responseFail(response, -32602, "暂无评价", "");
				return ;
			}
			
			JSONObject obj = new JSONObject();
			obj.accumulate("student_evaluation_total", setb);
			String format_json = this.FormatJson(0, "", Object2Json(obj));
			this.responseSuccess(response, format_json, 0);
			return;
		}
		catch(Exception e){
			e.printStackTrace();
			this.responseFail(response, -32602, "服务器有点忙，请过会重试", "");
			return ;
		}
	}
	
	/**
	 * 
	 * @param request
	 * @param response
	 */
	
	@RequestMapping(value = "/apply")
	public void apply(HttpServletRequest request,
			HttpServletResponse response){
		try{
			if( COMMON.isnull(request.getParameter("course"))
					|| COMMON.isnull(request.getParameter("max_size"))
					|| COMMON.isnull(request.getParameter("address"))
					|| COMMON.isnull(request.getParameter("time"))
					|| COMMON.isnull(request.getParameter("goal"))
					)
			{
				this.responseFail(response, -32602, "参数无效", "指定参数不符合服务接口定义");
				return ;
			}
			Integer max_size = 0;
			if(!request.getParameter("max_size").toString().isEmpty()){
				max_size = Integer.valueOf(request.getParameter("max_size").toString());
			}
			Integer period = 0;
			if(!request.getParameter("period").toString().isEmpty()){
				period = Integer.valueOf(request.getParameter("period").toString());
			}
			Integer goal = 0;
			if(!request.getParameter("goal").toString().isEmpty()){
				goal = Integer.valueOf(request.getParameter("goal").toString());
			}
			Integer wage = 0;
			if(!request.getParameter("wage").toString().isEmpty()){
				wage = Integer.valueOf(request.getParameter("wage").toString());
			}
			Integer bonus = 0;
			if(!request.getParameter("bonus").toString().isEmpty()){
				bonus = Integer.valueOf(request.getParameter("bonus").toString());
			}
			Integer id = Integer.valueOf(request.getParameter("id").toString());
			String reservation_number = OutTradeNo.createTradeNo(1001, id);
			String user_name = request.getParameter("user_name").toString();
			String school = request.getParameter("school").toString();
			String lecture = COMMON.NulltoBlank(request.getParameter("lecture").toString());
			String course = COMMON.NulltoBlank(request.getParameter("course").toString());
			String address = COMMON.NulltoBlank(request.getParameter("address").toString());
			Timestamp time = Timestamp.valueOf(request.getParameter("time").toString());
			Integer ispublic = COMMON.NulltoZero(Integer.valueOf(request.getParameter("ispublic").toString()));
			Integer administrator = COMMON.NulltoZero(Integer.valueOf(request.getParameter("administrator").toString()));
			Integer result = reservationService.apply(id, user_name, reservation_number, 
					school, lecture, course, max_size,
					address, time, period, goal, wage, bonus, ispublic, administrator);
			if(result == 0){
				this.responseFail(response, -32602, "预约单开始时间不能早于当前时间", "预约单开始时间不能早于当前时间");
				return ;
			}
			JSONObject obj = new JSONObject();
			obj.accumulate("result", result);
			String format_json = this.FormatJson(0, "", Object2Json(obj));
			this.responseSuccess(response, format_json, 0);
			return ;
		}
		catch(Exception e){
			e.printStackTrace();
			this.responseFail(response, -32602, "服务器有点忙，请过会重试", "");
			return ;
		}
	}
	
	/**
	 * 
	 * @param request
	 * @param response
	 */
	
	@RequestMapping(value = "/update")
	public void update(HttpServletRequest request,
			HttpServletResponse response){
		try{
			if( COMMON.isnull(request.getParameter("reservation_id"))
					|| COMMON.isnull(request.getParameter("max_size"))
					|| COMMON.isnull(request.getParameter("address"))
					|| COMMON.isnull(request.getParameter("time"))
					|| COMMON.isnull(request.getParameter("goal"))
					)
			{
				this.responseFail(response, -32602, "参数无效", "指定参数不符合服务接口定义");
				return ;
			}
			Integer reservation_id = Integer.valueOf(request.getParameter("reservation_id").toString());
			String school = request.getParameter("school").toString();
			String lecture = COMMON.NulltoBlank(request.getParameter("lecture").toString());
			Integer max_size = COMMON.NulltoZero(Integer.valueOf(request.getParameter("max_size").toString()));
			String address = COMMON.NulltoBlank(request.getParameter("address").toString());
			Timestamp time = Timestamp.valueOf(request.getParameter("time").toString());
			Integer period = COMMON.NulltoZero(Integer.valueOf(request.getParameter("period").toString()));
			Integer goal = COMMON.NulltoZero(Integer.valueOf(request.getParameter("goal").toString()));
			Integer wage = COMMON.NulltoZero(Integer.valueOf(request.getParameter("wage").toString()));
			Integer bonus = COMMON.NulltoZero(Integer.valueOf(request.getParameter("bonus").toString()));
			
			Integer result = reservationService.update(reservation_id, 
					school, lecture, max_size,
					address, time, period, goal, wage, bonus);
			if(result == -1){
				this.responseFail(response, -32602, "最大人数大于当前人数！", "指定参数不符合服务接口定义");
				return ;
			}
			else if(result == -2){
				this.responseFail(response, -32602, "此教师不存在！", "指定参数不符合服务接口定义");
				return ;
			}
			JSONObject obj = new JSONObject();
			obj.accumulate("result", result);
			String format_json = this.FormatJson(0, "", Object2Json(obj));
			this.responseSuccess(response, format_json, 0);
			return ;
		}
		catch(Exception e){
			e.printStackTrace();
			this.responseFail(response, -32602, "服务器有点忙，请过会重试", "");
			return ;
		}
	}
	
	/**
	 * 
	 * @param request
	 * @param response
	 */
	
	@RequestMapping(value = "/sendInvite")
	public void sendInvite(HttpServletRequest request,
			HttpServletResponse response){
		try{
			if( COMMON.isnull(request.getParameter("content"))
					|| COMMON.isnull(request.getParameter("user_id"))
					)
			{
				this.responseFail(response, -32602, "参数无效", "指定参数不符合服务接口定义");
				return ;
			}
			Integer user_id = Integer.valueOf(request.getParameter("user_id").toString());
			String content = request.getParameter("content").toString();
			
			Integer result = reservationService.sendInvite(user_id, content);
			remindService.addNewRemind(1,0,0);
			JSONObject obj = new JSONObject();
			obj.accumulate("result", result);
			String format_json = this.FormatJson(0, "", Object2Json(obj));
			this.responseSuccess(response, format_json, 0);
			return ;
		}
		catch(Exception e){
			e.printStackTrace();
			this.responseFail(response, -32602, "服务器有点忙，请过会重试", "");
			return ;
		}
	}

}
